package org.mydzms.com.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.dzms.entity.Userinfos;
import org.mydzms.services.personl.PersoalServices;

/**
 * Servlet implementation class PersonalAccountServlet
 */
public class PersonalAccountServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	private PersoalServices personalServices = new PersoalServices();

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		String newpassword =request.getParameter("newpassword");
		String userid = request.getParameter("userid");
		int id = Integer.parseInt(userid);
		
		Userinfos us = new Userinfos();
		us.setPassword(newpassword);
		us.setUserid(id);
		
//		request.setAttribute("newpassword", newpassword);
//		PrintWriter out = response.getWriter();
//		if (newpassword!=null) {
//			out.print("true");
//		} else{
//			out.print("false");
//		}
//		out.flush();
//		out.close();
		
		
		personalServices.updatePassword(us);
		request.getRequestDispatcher("personal.jsp").forward(request, response);

	}

}
